package cn.tedu.springdemo.bean;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.stereotype.Component;

import java.util.Iterator;

@Component
public class BeanFactoryPostProcessorDemo
    implements BeanFactoryPostProcessor {

    private static Logger logger = LoggerFactory.getLogger(
            BeanFactoryPostProcessorDemo.class);

    @Override
    public void postProcessBeanFactory(
            ConfigurableListableBeanFactory
                    configurableListableBeanFactory)
            throws BeansException {
        //此方法, 在Spring扫描完成所有的JavaBean定义以后执行
        //可以得到全部的JavaBean定义信息
        Iterator<String> names =
                configurableListableBeanFactory.getBeanNamesIterator();
        while (names.hasNext()){
            //System.out.println(names.next());
            logger.debug(names.next());
        }
    }
}
